//
//  accountAndSafeController.m
//  pacc
//
//  Created by 测试 on 2018/5/21.
//  Copyright © 2018年 测试. All rights reserved.
//

#import "accountAndSafeController.h"
#import "ZXTabBarController.h"
#import "loginViewController.h"
#import "changePhoneNumberController.h"
#import "changepasswordController.h"
@interface accountAndSafeController ()<RHURLRequestDelegate,UITextFieldDelegate>
- (IBAction)changePhoneClick:(UIButton *)sender;
@property(strong,nonatomic)NetWorking *request;
@property (weak, nonatomic) IBOutlet UILabel *phoneLabel;
@property (weak, nonatomic) IBOutlet UILabel *userLabel;

@end

@implementation accountAndSafeController
- (IBAction)changeLoginSec:(id)sender {
    changepasswordController *vc = [changepasswordController new];
    self.title = @"修改密码";
    vc.isHidden = YES;
    vc.isFromWO = YES;
    [self.navigationController pushViewController:vc animated:YES];

}
- (IBAction)quitLogin:(id)sender {
    NSLog(@"退出登录");
}
- (IBAction)quitLoginBtnClick:(UIButton *)sender {
//    return;
//    [self setupLoginViewController];
    NSMutableDictionary * dic =[NSMutableDictionary dictionary];

    [dic setValue:my_AppDelegate.registrationId forKey:@"registrationId"];
    [dic setValue:my_AppDelegate.token forKey:@"token"];
    [self setupLoginViewController];
    [NetWorking startPOSTRequestWithUrl:[NSString stringWithFormat:@"userappLogout"] parameters:dic logMes:@"退出登录" show:NO success:^(NSDictionary *data) {
        NSString *status = [NSString stringWithFormat:@"%@",[data valueForKey:@"status"]];
        if ([status isEqualToString:@"200"]) {
            dispatch_async(dispatch_get_main_queue(), ^{
            });
        }else{
//            [SVProgressHUD showErrorWithStatus:@"退出失败"];
        }
        
    } failure:^(NSError *error) {
//        [SVProgressHUD showErrorWithStatus:@"连接超时"];
    }];
}
- (void)requestDidSuccessData:(id)data {
}
-(void)requestDidFailedError:(NSError *)error{
    NSLog(@"%@", error.localizedDescription);
}

#pragma mark - 懒加载

- (IBAction)changePhoneClick:(UIButton *)sender {
    changePhoneNumberController *vc = [changePhoneNumberController new];
    vc.isFromWO = YES;
    self.title = @"修改手机号";
    [self.navigationController pushViewController:vc animated:YES];
}

- (NetWorking *)request {
    
    if (!_request) {
        _request = [[NetWorking alloc] init];
        _request.delegate = self;
    }
    return _request;
}

//进入登录页面
- (void)setupLoginViewController
{
    [my_AppDelegate.window.rootViewController dismissViewControllerAnimated:YES completion:nil];
    loginViewController *loginVc = [[loginViewController alloc] init];
    UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:loginVc];
    my_AppDelegate.window.rootViewController = nav;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = baseBackgroundColor;
    self.phoneLabel.text = _phone;
    self.userLabel.text = self.userName;
    // Do any additional setup after loading the view from its nib.
}
-(void)viewWillAppear:(BOOL)animated{
    self.title = @"账号与安全";
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
